<template>
  <!-- 人员移动轨迹 -->
  <div class="vehiclemovetrack">
    <basic-container>
      <avue-crud
        :option="option"
        :table-loading="loading"
        :data="data"
        :page.sync="page"
        :before-open="beforeOpen"
        v-model="form"
        ref="crud"
        @search-change="searchChange"
        @search-reset="searchReset"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
      >
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { getList } from "@/api/useronduty/vehiclemovetrack";
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      form: {},
      query: {},
      data: [],
      loading: true,
      page: {
        pageSize: this.$pageSize,
        currentPage: 1,
        total: 0
      },
      option: {
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchSpan: 5,
        searchMenuSpan: 4,
        border: true,
        index: false,
        menu: false,
        addBtn: false,
        selection: false,
        refreshBtn: true,
        columnBtn: false,
        dialogClickModal: false,
        column: [
          {
            label: "车辆名称",
            prop: "name",
            align: "center",
            search: true
          },
          {
            label: "经度",
            prop: "jd",
            align: "center"
          },
          {
            label: "纬度",
            prop: "wd",
            align: "center"
          },
          {
            label: "时间",
            prop: "sj",
            align: "center"
          },
          {
            label: "卡号",
            prop: "kh",
            align: "center"
          }
        ]
      }
    };
  },
  computed: {
    ...mapGetters(["permission"])
  },
  mounted() {
    this.onLoad(this.page);
  },
  methods: {

    // 清空搜索条件
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },

    // 搜索条件改变事件
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },

    // 换页数
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page);
    },

    // 换每页显示数量
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page);
    },

    // 刷新
    refreshChange() {
      this.onLoad(this.page, this.query);
    },

    // 获取表格内容
    onLoad(page, params = {}) {
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
    }
  }
};
</script>

<style lang="scss" scpoed>
.vehiclemovetrack {
  .avue-crud {
    .avue-crud__search {
      .avue-form__row:nth-child(1) {
        .el-form-item__label {
          text-align: unset;
        }
      }
    }
  }
}
</style>